﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BTKERP.Model;
using BTKERP.BLL.Inventory;

namespace BTKERP.MVCWeb.Controllers
{
    public class CategoryController : ControllerBase
    {
        //
        // GET: /Category/
        
        public ActionResult Index()
        {
            List<Category> categories = InventoryInfoMgt.GetCategories();
            return View(categories);
        }

        //
        // GET: /Category/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Category/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Category/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // POST: /Category/Edit/5

        [HttpPost]
        public JsonResult Edit(Guid tid, string tname,string tdesc,int groups)
        {
            try
            {
                InventoryInfoMgt.UpdateCategory(tid, tname, tdesc, "Test UserName");
                return Json(new { result = 1 });
            }
            catch (Exception ex)
            {
                return Json(new { result = 0 });
            }
        }

      
        //
        // POST: /Category/Delete/5

        [HttpPost]
        public JsonResult Delete(Guid id)
        {
            try
            {
                if (InventoryInfoMgt.DeleteCategory(id))
                {
                    return Json(new { result = 1 });
                }
                else
                {
                    return Json(new { result = 0 });
                }
            }
            catch (Exception ex)
            {
                return Json(new { result = 0 });
            }
        }
    }
}
